package com.example.mytest.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class ChannelFile {
    static String path = "E:\\xiazaizhan\\xiazaizhan1_75\\";

    public static void main(String[] args) {
        writeChannel();
//        writeAppName();
    }

    static void writeChannel(){
        String sourceFile = path + "name.txt";
        String channelFile = path + "channel.txt";
        try {
            int id = 1;
            BufferedWriter out = new BufferedWriter(new FileWriter(channelFile));
            File file = new File(sourceFile);
            InputStreamReader inputReader = new InputStreamReader(new FileInputStream(file));
            BufferedReader bf = new BufferedReader(inputReader);
            String str = "app%d{\n" +
                    "            buildConfigField \"String\", \"desktop_app_name\", \"\\\"%s\\\"\"\n" +
                    "            manifestPlaceholders = [\n" +
                    "                    UMENG_CHANNEL_VALUE: \"xiazaizhan1\",\n" +
                    "                    desktop_name: \"%s\",\n" +
                    "                    desktop_icon: \"@mipmap/ic_launcher_%d\"\n" +
                    "            ]\n" +
                    "        }\n";
//            String str = "app%d{\n" +
//                    "            manifestPlaceholders = [\n" +
//                    "                    UMENG_CHANNEL_VALUE: \"xiazaizhan1\",\n" +
//                    "                    desktop_name: \"%s\",\n" +
//                    "                    desktop_icon: \"@mipmap/ic_launcher_%d\"\n" +
//                    "            ]\n" +
//                    "        }\n";
            String appName;
            while ((appName = bf.readLine()) != null) {
                out.write(String.format(str, id, appName, appName, id));
                ++id;
            }
            bf.close();
            inputReader.close();
            out.close();
            System.out.println("文件创建成功！");
        } catch (IOException e) {
        }
    }

    static void writeAppName(){
        String sourceFile = path + "name.txt";
        String channelFile = path + "app_name.txt";
        try {
            int id = 1;
            BufferedWriter out = new BufferedWriter(new FileWriter(channelFile));
            File file = new File(sourceFile);
            InputStreamReader inputReader = new InputStreamReader(new FileInputStream(file));
            BufferedReader bf = new BufferedReader(inputReader);
            String str = "app%d{\n" +
                    "            buildConfigField \"String\", \"desktop_app_name\", \"\\\"%s\\\"\"\n" +
                    "        }\n";
            String appName;
            while ((appName = bf.readLine()) != null) {
                out.write(String.format(str, id, appName));
                ++id;
            }
            bf.close();
            inputReader.close();
            out.close();
            System.out.println("文件创建成功！");
        } catch (IOException e) {
        }
    }
}
